import os

import paramiko
from PyQt5.QtCore import Qt, QSettings,pyqtSignal
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel, QTextBrowser, QLineEdit, QSplashScreen,QDesktopWidget
# from util.ThreadDownimage import DownImage
from util.Tools import ssh

# settings = QSettings(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config\\config.ini"),
#                      QSettings.IniFormat)
# settings.setIniCodec("UTF-8")

class InitImage(QSplashScreen):
    def __init__(self,BasePath):
        super(InitImage,self).__init__()
        self.resize(800,500)
        self.setUI()
        self.setCent()
        self.setLeftImage(BasePath)
        self.setReightImage()
        self.Progress()
        self.GetInitIMage(BasePath)
    def setCent(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def setUI(self):
        self.LeftImage = QWidget(self)
        self.LeftImage.setGeometry(20,50,360,360)
        self.ReightImage = QWidget(self)
        self.ReightImage.setGeometry(450,100,360,50)
        self.ProgressReightImage = QWidget(self)
        self.ProgressReightImage.setGeometry(410, 350, 380, 30)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)


    def setLeftImage(self,path):
        newQlabel = QLabel(self.LeftImage)
        InitImagePath = os.path.join(path,"image\\initimage\\1.jpg")
        pix = QPixmap(InitImagePath, "0", Qt.AvoidDither | Qt.ThresholdDither | Qt.ThresholdAlphaDither)
        newQlabel.setPixmap(pix)
        newQlabel.setScaledContents(True)
        newQlabel.resize(self.LeftImage.width(),self.LeftImage.height())

    def setReightImage(self):
        iniQtext = QTextBrowser(self.ReightImage)
        iniQtext.setObjectName("txtpro")
        iniQtext.setText("初始化中.....")
        iniQtext.setHorizontalScrollBarPolicy(1)
        iniQtext.setVerticalScrollBarPolicy(1)
        iniQtext.setAlignment(Qt.AlignLeft)
        iniQtext.setStyleSheet(
            "#txtpro{background: transparent;background-color: transparent;border:none;font-size:35px}")
    def Progress(self):
        self.preQtext = QLineEdit(self.ProgressReightImage)
        self.preQtext.setObjectName("txtpro")
        self.preQtext.setAlignment(Qt.AlignLeft)

    def GetInitIMage(self,path):

        pass

    def showReightPressLine(self,str):
        self.preQtext.setText(str)

    def mousePressEvent(self, event):
        '''
        鼠标左右键点击事件
        计算点击点的位置
        :param event:
        :return:
        '''
        if event.button() == Qt.RightButton:
            self.close()